package org.example.http.demo;

import com.google.gson.Gson;
import org.example.http.*;

import java.io.IOException;
import java.util.Map;

public class MyInfoServlet extends HttpServletImpl {
    Gson gson = new Gson();
    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws IOException, ServletException {
        HttpSession session = request.getSession();
        String username = (String) session.getAttribute("username");
        response.setContentType("application/json;charset=utf-8");
        if(username == null){
            gson.toJson(Map.of("code", 0, "msg", "未登录"),
                    response.getWriter());
        } else {
            gson.toJson(Map.of("code", 1, "msg", "已登录 ", "data", username),
                    response.getWriter());
        }
    }
}
